//
//  DiseaseDetailViewController.m
//  project_delicious
//
//  Created by dlios on 15-3-24.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DiseaseDetailViewController.h"
#import "CollectionViewController.h"
#import "DisCollectViewController.h"
#import "DiseaseTabCell.h"
#import "UIColor+AddColor.h"

@interface DiseaseDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) NSArray *arr;
@property (nonatomic, retain) NSArray *arr1;
@property (nonatomic, retain) MBProgressHUD *hud;
@property (nonatomic, retain) NSString *str;

@end

@implementation DiseaseDetailViewController
- (void)dealloc
{
    [_hud release];
    [_arr release];
    [_str release];
    [_dic release];
    [_arr1 release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorColor = [UIColor clearColor];
    [self.view addSubview:tableView];
    [tableView release];
    [tableView registerClass:[DiseaseTabCell class] forCellReuseIdentifier:@"guo"];
    self.arr = @[@"病症简介", @"饮食保健", @"生活保健"];
    NSString *str = [self.dic objectForKey:@"diseaseDescribe"];
    NSString *str1 = [self.dic objectForKey:@"fitEat"];
    NSString *str2 = [self.dic objectForKey:@"lifeSuit"];
    self.arr1 = @[str, str1, str2];

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.arr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"A";
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //分区顶部的高度
    return self.view.frame.size.height / 12;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = [UIColor turquoiseColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = [self.arr objectAtIndex:section];
    
    return [label autorelease];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    NSString *str = [self.arr1 objectAtIndex:indexPath.section];
    CGRect rect = [str boundingRectWithSize:CGSizeMake(tableView.frame.size.width - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height + 30;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DiseaseTabCell *cell = [tableView dequeueReusableCellWithIdentifier:@"guo"];
    
//    cell.accessoryType = UITableViewCellAccessoryCheckmark
    cell.textLabel.text = [self.arr1 objectAtIndex:indexPath.section];
    
    NSLog(@"%@", NSStringFromCGSize(cell.textLabel.frame.size));

    cell.textLabel.numberOfLines = 0;
    [cell.textLabel sizeToFit];
    //cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"foodcoB.png"]];
    cell.userInteractionEnabled = NO;
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
